<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\CoComplaint;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class CoComplaintController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new CoComplaint(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->name;
            $grid->tel;
            $grid->type->display(function ($k){
                if($k==1){
                    return '用户';
                }else{
                    return '配送员';
                }
            });
//            $grid->content;
            $grid->grade;
            $grid->grade1;

//            $grid->remarks;


            $grid->status->display(function ($k){
                if($k==1){
                    return '待查看';
                }else{
                    return '已查看';
                }
            });
//            $grid->user_id;
            $grid->created_at;
            $grid->updated_at->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableCreateButton();
            $grid->disableViewButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CoComplaint(), function (Show $show) {
            $show->id;
            $show->content;
            $show->grade;
            $show->grade1;
            $show->name;
            $show->remarks;
            $show->status;
            $show->tel;
            $show->type;
            $show->user_id;
            $show->created_at;
            $show->updated_at;
            $show->disableEditButton();
            $show->disableDeleteButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CoComplaint(), function (Form $form) {
            $form->hidden('id');
            $form->display('name');
            $form->display('tel');
            $form->display('grade');
            $form->display('grade1');
            $form->display('content');
            $form->text('remarks');
            $form->hidden('status')->value(2);
//            $form->hidden('status')->default(2);
            $form->radio('type')->options(['1'=>'用户','2'=>'配送员'])->disable();
//            $form->display('type');
//            $form->display('user_id');

            $form->display('created_at');
//            $form->display('updated_at');
            $form->disableViewButton();
            $form->footer(function ($footer) {
                // 去掉`重置`按钮
                $footer->disableReset();

                // 去掉`查看`checkbox
                $footer->disableViewCheck();

                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();

                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
            $form->saving(function (Form $form) {

                $form->status = 2;
            });
        });
    }
}
